package com.feri.rbacsys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feri.rbacsys.entity.Supplier;
import com.feri.rbacsys.mapper.SupplierMapper;
import com.feri.rbacsys.service.SupplierService;
import com.feri.rbacsys.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 神经质的木子李
 * @description 针对表【t_supplier】的数据库操作Service实现
 * @createDate 2023-03-28 15:31:29
 */
@Service
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier>
        implements SupplierService {
    @Resource
    private SupplierMapper mapper;

    @Override
    public R add(Supplier supplier) {
        if (supplier != null) {
            if (mapper.insert(supplier) > 0) {
                return R.ok();
            }
        }
        return R.fail("添加失败");
    }

    @Override
    public R deleteFlag(int id) {
        if (mapper.deleteFlag(id) > 0) {
            return R.ok();
        }
        return R.fail();
    }

    @Override
    public R revert(int id) {
        if (mapper.revert(id) > 0) {
            return R.ok();
        }
        return R.fail();
    }

    @Override
    public R delList(int page, int size) {
        QueryWrapper<Supplier> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("delFlag", 0);
        return R.ok(mapper.selectList(queryWrapper));
    }

    @Override
    public R supList(int page, int size) {
        QueryWrapper<Supplier> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("delFlag", 1);
        Page<Supplier> page1 = mapper.selectPage(new Page<>(page, size), queryWrapper);
        return R.ok(page1);
    }
}




